<template>
    <div>
        <el-form :inline="true" :model="inRegister" class="search-form" style="margin-top:10px" label-width="100px">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="车牌号">
                        <el-input style="width:150px" v-model="inRegister.plateNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-checkbox v-model="isDouble" @change="handleCheck">双 柜</el-checkbox>
                </el-col>
            </el-row>
        </el-form>
        <div class="border-line-dashed"></div>
        <container-form :container="containerOne"></container-form>
        <div class="border-line-dashed"></div>
        <container-form :container="containerTwo" :containerNoShow="!isDouble"></container-form>
        <div class="border-line-dashed"></div>
        <div style="text-align: center" class="mt-10">
            <el-button type="primary" v-if="power('WJOB_GATE_CONTAINER_REGISTER:ADD')" @click="handleSubmit" :loading="$store.getters.loadingBtn">确认进港</el-button>
        </div>
    </div>
</template>

<script>
import containerForm from './containerForm.vue';
import {gateContainerIn} from '@/api/middleControl/middleControl';
export default {
    components: {
        containerForm
    },
    data () {
        return {
            inRegister:{},
            containerOne:this.clearForm(),
            containerTwo:this.clearForm(),
            isDouble:false
        }
    },
    methods: {
        // 确认进港
        handleSubmit(){
            let container=[]
            if(this.isDouble){
                container.push(this.containerOne,this.containerTwo)
                if(!container[1].containerNo){
                    this.$message({message:'请填写第二个箱信息',type:'error'})
                    return
                }
            }else{
                container.push(this.containerOne)
            }
            if(!container[0].containerNo){
                this.$message({message:'请填写第一个箱信息',type:'error'})
                return
            }
            let data={
                plateNumber:this.inRegister.plateNumber,
                isDouble:this.isDouble,
                container,
            }
            if(!data.plateNumber){
                this.$message({message:'请先填写车牌号',type:'error'})
                return
            }

            gateContainerIn(data).then(res=>{
                this.$message({message:'登记成功!',type:'success'})
                const id=res.data.registerId
                this.inRegister.plateNumber = "";
                this.containerOne=this.clearForm()
                this.containerTwo=this.clearForm()
                this.$emit('load')
                const origin = window.location.origin+window.location.pathname
                window.open(origin + '#/TicketPrint?id=' + id)
            })
        },
        clearForm(){
            return {
                containerNo:'',
                entrustNo:'',
                containerType:'',
                containerSize:'',
                ifHeavy:'',
                tradeType:'',
                ownerName:'',
                ownerId:'',
                cargoName:'',
                cargoWeight:'',
                importAndExport:'',
            }
        },
        handleCheck(bool){
            this.containerTwo=this.clearForm()
        }
    }
};
</script>

<style>
</style>
